<template>
    <i-row>
        <i-tabs v-model="currentTab" @on-click="getFlows(null, null)">
            <i-tab-pane label="按机位申请实验室" name="按机位申请实验室">
                <i-table :columns="columns" :data="tableData" :loading="loading">、
                    <template slot="Action" slot-scope="{row}">
                        <i-button @click="checkWorkflow(row)">查看</i-button>
                    </template>
                </i-table>
                <i-page style="margin-top: 8px" :page-size="page.seat.pageSize" :total="page.seat.totalRow" show-total show-sizer @on-page-size-change="getFlows(null, $event)" @on-change="getFlows($event, null)"/>
            </i-tab-pane>
            <i-tab-pane label="按团队申请实验室" name="按团队申请实验室">
                <i-table :columns="columns" :data="tableData" :loading="loading">、
                    <template slot="Action" slot-scope="{row}">
                        <i-button @click="checkWorkflow(row)">查看</i-button>
                    </template>
                </i-table>
                <i-page style="margin-top: 8px" :page-size="page.room.pageSize" :total="page.room.totalRow" show-total show-sizer @on-page-size-change="getFlows(null, $event)" @on-change="getFlows($event, null)"/>
            </i-tab-pane>
            <i-tab-pane label="申请演武创客空间" name="按团队申请创客空间">
                <i-table :columns="columns" :data="tableData" :loading="loading">、
                    <template slot="Action" slot-scope="{row}">
                        <i-button @click="checkWorkflow(row)">查看</i-button>
                    </template>
                </i-table>
                <i-page style="margin-top: 8px" :page-size="page.ywck.pageSize" :total="page.ywck.totalRow" show-total show-sizer @on-page-size-change="getFlows(null, $event)" @on-change="getFlows($event, null)"/>
            </i-tab-pane>
        </i-tabs>
    </i-row>
</template>
<script>
import axios from 'axios';
let app = require("@/config");
export default {
    data () {
        return {
            loading: false,
            currentTab: "按机位申请实验室",
            tableData: [],
            page: {
                seat: {
                    page: 1,
                    pageSize: 20,
                    totalRow: 0
                },
                room: {
                    page: 1,
                    pageSize: 20,
                    totalRow: 0
                },
                ywck: {
                    page: 1,
                    pageSize: 20,
                    totalRow: 0
                }
            },
            dic2: {
               '按机位申请实验室': 'seat',
               '按团队申请实验室': 'room',
               '按团队申请创客空间': 'ywck'
            },
            columns: [
                {
                    title: "流程名称",
                    key: "WorkflowName"
                },
                {
                    title: "流程类别",
                    key: "WorkflowType"
                },
                {
                    title: "申请人",
                    key: "Owner"
                },
                {
                    title: "申请时间",
                    key: "ArriveOn"
                },
                {
                    title: "申请版本",
                    key: "Version"
                },
                {
                    title: "操作",
                    slot: "Action"
                }
            ],
            dic: {
                "按机位申请实验室": "/manage/org/orgdetailform",
                "按团队申请实验室": "/manage/org/activityform",
                "按团队申请创客空间": "/manage/app-form/marker-space"
            }
        }
    },
    mounted () {
        app.title = "所有流程";
        this.getFlows();
    },
    methods: {
        getFlows (tpage, tpageSize) {
            let page = tpage || this.page[this.dic2[this.currentTab]].page;
            let pageSize = tpageSize || this.page[this.dic2[this.currentTab]].pageSize;
            this.loading = true;
            axios.post("/api/workflow/AllFlow", {name: this.currentTab, page, pageSize}, msg => {
                if (msg.success) {
                    this.page[this.dic2[this.currentTab]].totalRow = msg.totalRow;
                    this.page[this.dic2[this.currentTab]].page = msg.page;
                    this.page[this.dic2[this.currentTab]].pageSize = msg.pageSize;
                    this.tableData = msg.data;
                } else {
                    this.$Message.warning(msg.msg);
                }
                this.loading = false;
            });
        },
        checkWorkflow (row) {
            window.open(`${this.dic[row.WorkflowType]}?instanceId=${row.InstanceId}&stepId=${row.StepId}&detail=true`);
        }
    }
}
</script>
